#ifndef __CCHTTPREQUEST_H__
#define __CCHTTPREQUEST_H__

#include "ZHttpRequest.h"
#include "ZHttpResponse.h"
#include "ZHttpClient.h"
#include "ZScheduler.h"

namespace ZuiLib {

/** @brief Singleton that handles asynchrounous http requests
 * Once the request completed, a callback will issued in main thread when it provided during make request
 */
class ZHttpClient
{
public:
	ZUI_CLASS_NAME("zui.HttpClient");

    /** Return the shared instance **/
    static ZHttpClient *getInstance();
    
    /** Relase the shared instance **/
    static void destroyInstance();

    /** Enable cookie support. **/
    void enableCookies(const char* cookieFile);
        
    /**
     * Add a get request to task queue
     * @param request a HttpRequest object, which includes url, response callback etc.
                      please make sure request->_requestData is clear before calling "send" here.
     */
    void send(ZHttpRequestPtr request);

    /**
     * Immediate send a request
     * @param request a HttpRequest object, which includes url, response callback etc.
                      please make sure request->_requestData is clear before calling "sendImmediate" here.
     */
    void sendImmediate(ZHttpRequestPtr request);
  
    
    /**
     * Change the connect timeout
     * @param value The desired timeout.
     */
    inline void setTimeoutForConnect(int value) {_timeoutForConnect = value;};
    
    /**
     * Get connect timeout
     * @return int
     */
    inline int getTimeoutForConnect() {return _timeoutForConnect;}
    
    
    /**
     * Change the download timeout
     * @param value
     */
    inline void setTimeoutForRead(int value) {_timeoutForRead = value;};
    

    /**
     * Get download timeout
     * @return int
     */
    inline int getTimeoutForRead() {return _timeoutForRead;};
        
private:
    ZHttpClient();
    virtual ~ZHttpClient();
private:
    int _timeoutForConnect;
    int _timeoutForRead;
};

// end of Network group
/// @}

}


#endif //__CCHTTPREQUEST_H__
